﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:props="clr-namespace:ScrumFactory.Windows.Properties"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:SF_Converters="clr-namespace:ScrumFactory.Windows.Helpers.Converters;assembly=ScrumFactory.Windows.Helpers">

    <SF_Converters:ToLowerConverter x:Key="ToLowerConverter" />
    
    
    <ControlTemplate x:Key="TopMenu_TopLevelItem" TargetType="{x:Type MenuItem}">        
        <Border x:Name="border" Margin="3,0,3,0" Cursor="Hand" VerticalAlignment="Center">
            <ContentPresenter ContentSource="Header" RecognizesAccessKey="True" HorizontalAlignment="Center">
                <ContentPresenter.Resources>
                    <Style TargetType="TextBlock">
                        <Setter Property="Foreground" Value="{StaticResource TopMenuBrush}"/>
                        <Setter Property="VerticalAlignment" Value="Center"/>
                        <Style.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter Property="TextDecorations" Value="Underline"/>
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </ContentPresenter.Resources>
            </ContentPresenter>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="IsEnabled" Value="False">
                <Setter TargetName="border" Property="Opacity" Value="0.5"/>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <ControlTemplate x:Key="TopMenu_SubmenuItem" TargetType="{x:Type MenuItem}">
        <Border x:Name="border" Margin="0" Padding="3" Cursor="Hand" CornerRadius="0" HorizontalAlignment="Stretch" Background="{TemplateBinding Background}">
            <Grid Margin="20,6,20,6" HorizontalAlignment="Stretch">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="auto" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <ContentPresenter Grid.Column="0" ContentSource="Icon" Margin="0,0,5,0" HorizontalAlignment="Center" VerticalAlignment="Center" />
                <ContentPresenter Grid.Column="1"
                                  TextElement.FontSize="{StaticResource BigFontSize}"
                                  ContentSource="Header" RecognizesAccessKey="True" HorizontalAlignment="Left" VerticalAlignment="Center"/>
                <CheckBox 
                    x:Name="checkbox"
                    Grid.Column="1"
                    HorizontalAlignment="Right" Visibility="Collapsed"
                    IsChecked="{TemplateBinding IsChecked}" />    
            </Grid>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="IsEnabled" Value="False">
                <Setter TargetName="border" Property="Opacity" Value="0.5"/>
            </Trigger>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter TargetName="border" Property="Background" Value="{StaticResource TopMenuSelectedItemBackground}"/>
                <Setter TargetName="border" Property="TextBlock.Foreground" Value="{StaticResource TopMenuSelectedItemBrush}"/>                    
            </Trigger>
            <!--<Trigger Property="IsMouseOver" Value="False">
                <Setter TargetName="border" Property="Background" Value="Transparent"/>                
            </Trigger-->
            <Trigger Property="IsCheckable" Value="True">
                <Setter TargetName="checkbox" Property="Visibility" Value="Visible"/>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <ControlTemplate x:Key="TopMenu_TopLevelHeader" TargetType="MenuItem">
        <Grid x:Name="grid" >
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>

            

            <Border Grid.Column="0" x:Name="border" Margin="3,0,3,0" Cursor="Hand" VerticalAlignment="Center" >
                <ContentPresenter ContentSource="Header" RecognizesAccessKey="True">
                    <ContentPresenter.Resources>
                        <Style TargetType="TextBlock">
                            <Setter Property="Foreground" Value="{StaticResource TopMenuBrush}"/>
                            <Style.Triggers>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter Property="TextDecorations" Value="Underline"/>
                                </Trigger>
                            </Style.Triggers>
                        </Style>
                    </ContentPresenter.Resources>
                </ContentPresenter>
            </Border>

            <ContentPresenter Grid.Column="1" ContentSource="Icon" Margin="10,0,0,0" HorizontalAlignment="Center" VerticalAlignment="Center" />

            <Popup 
                                    Name="Popup"
                                    Placement="Bottom"                                    
                                    StaysOpen="True"               
                                    IsOpen="{TemplateBinding IsSubmenuOpen}"
                                    AllowsTransparency="True" 
                                    Focusable="False"
                                    PopupAnimation="Fade">
                <Border
                                        Margin="0,0,5,5"
                                        CornerRadius="0"
                                        Name="SubmenuBorder"                              
                                        Background="{StaticResource ToolBarMenuDropDownBackground}"
                                        BorderBrush="{StaticResource ToolBarMenuBorderBrush}"
                                        BorderThickness="2">
                    <StackPanel                                            
                                            IsItemsHost="True"
                                            KeyboardNavigation.DirectionalNavigation="Cycle" />
                    <Border.Effect>
                        <DropShadowEffect ShadowDepth="2" Opacity="0.5" />
                    </Border.Effect>
                </Border>
            </Popup>
        </Grid>

        <ControlTemplate.Triggers>            
            <Trigger Property="IsEnabled" Value="False">
                <Setter TargetName="border" Property="Opacity" Value="0.5"/>
            </Trigger>

            
        </ControlTemplate.Triggers>

    </ControlTemplate>

    

    <Style TargetType="{x:Type MenuItem}">
        <Setter Property="OverridesDefaultStyle" Value="True"/>        
        <Setter Property="ItemContainerStyle">
            <Setter.Value>
                <Style TargetType="MenuItem">
                    <Setter Property="Template" Value="{StaticResource TopMenu_SubmenuItem}"/>
                </Style>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <Trigger Property="Role" Value="TopLevelHeader">
                <Setter Property="Template" Value="{StaticResource TopMenu_TopLevelHeader}"/>
                <Setter Property="Grid.IsSharedSizeScope" Value="true"/>
            </Trigger>
            <Trigger Property="Role" Value="TopLevelItem">
                <Setter Property="Template" Value="{StaticResource TopMenu_TopLevelItem}"/>
            </Trigger>
            <Trigger Property="Role" Value="SubmenuHeader">
                <Setter Property="Template" Value="{StaticResource TopMenu_SubmenuItem}"/>
            </Trigger>
            <Trigger Property="Role" Value="SubmenuItem">
                <Setter Property="Template" Value="{StaticResource TopMenu_TopLevelItem}"/>
            </Trigger>
        </Style.Triggers>

    </Style>

    <Style x:Key="SimpleSeparator" TargetType="Separator">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Separator">
                    <TextBlock Text="|" Foreground="{StaticResource TopMenuBrush}" Margin="3,0,3,0" VerticalAlignment="Center"/>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    

    <Style TargetType="{x:Type Menu}">        
        <Setter Property="Padding" Value="0,0,0,0"/>
        <Setter Property="BorderThickness" Value="0"/>
        <Setter Property="Margin" Value="5,0,0,0"/>
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="Foreground" Value="{StaticResource TopMenuItemBrush}"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Menu">                    
                    <StackPanel ClipToBounds="True" Orientation="Horizontal" IsItemsHost="True" Margin="{TemplateBinding Padding}"/>                    
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!-- TOOLBARS MENUS -->
    <ControlTemplate x:Key="ToolBarMenu_TopLevelItem" TargetType="{x:Type MenuItem}">        
        <Border x:Name="border" 
                CornerRadius="0" 
                Style="{StaticResource MouseOverBorder}"
                Cursor="Hand" 
                Margin="0,0,0,0"
                MinWidth="{TemplateBinding MinWidth}" MaxWidth="{TemplateBinding MaxWidth}">
        
            <Grid>                
                <Grid.RowDefinitions>
                    <RowDefinition Height="38"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <ContentPresenter x:Name="icon" Grid.Row="0" ContentSource="Icon" Margin="0,0,0,0" HorizontalAlignment="Center" VerticalAlignment="Center" />


                <!--<TextBlock Grid.Row="1" 
                           Margin="0,3,0,0"
                           FontSize="{StaticResource SmallFontSize}" Text="{TemplateBinding Header}" FontFamily="Arial" TextAlignment="Center" TextWrapping="Wrap" Foreground="{StaticResource ToolBarItemBrush}" />-->


                <ContentPresenter  
                        Grid.Row="1"
                        TextBlock.FontFamily="Arial"
                        TextBlock.FontSize="{StaticResource SmallFontSize}"
                        ContentSource="Header" RecognizesAccessKey="True" HorizontalAlignment="Center" VerticalAlignment="Center">
                    <ContentPresenter.Resources>
                        <Style TargetType="{x:Type TextBlock}">
                            <Setter Property="TextAlignment" Value="Center"/>
                            <Setter Property="TextWrapping" Value="Wrap"/>                            
                            <Setter Property="Foreground" Value="{StaticResource ToolBarItemBrush}"/>
                        </Style>
                    </ContentPresenter.Resources>
                </ContentPresenter>

            </Grid>
        </Border>
        <ControlTemplate.Triggers>
        
            <Trigger Property="IsEnabled" Value="False">
                <Setter TargetName="border" Property="Opacity" Value="0.5"/>
            </Trigger>
            <Trigger Property="IsChecked" Value="True">
                <Setter TargetName="border" Property="Background">
                    <Setter.Value>
                        <SolidColorBrush Color="White" Opacity="0.5"/>
                    </Setter.Value>
                </Setter>
                <Setter TargetName="border" Property="BorderBrush" Value="White"/>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <ControlTemplate x:Key="ToolBarMenu_SubmenuItem" TargetType="{x:Type MenuItem}">
        <Border x:Name="border" Margin="0" Padding="3" Cursor="Hand" TextBlock.Foreground="{StaticResource TopMenuItemBrush}">
            <Grid Margin="2,2,20,2" >
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="auto" />
                    <ColumnDefinition Width="auto" />
                </Grid.ColumnDefinitions>
                <ContentPresenter Grid.Column="0" ContentSource="Icon" Margin="0,0,5,0" HorizontalAlignment="Center" VerticalAlignment="Center" />                
                <ContentPresenter Grid.Column="1" 
                                  TextElement.FontSize="{StaticResource BigFontSize}"                               
                                  ContentSource="Header" 
                                  RecognizesAccessKey="True" HorizontalAlignment="Left" VerticalAlignment="Center">
                    <ContentPresenter.Resources>
                    </ContentPresenter.Resources>
                </ContentPresenter>
            </Grid>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="IsEnabled" Value="False">
                <Setter TargetName="border" Property="Opacity" Value="0.5"/>
            </Trigger>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter TargetName="border" Property="Background" Value="{StaticResource TopMenuSelectedItemBackground}"/>
                <Setter TargetName="border" Property="TextBlock.Foreground" Value="{StaticResource TopMenuSelectedItemBrush}"/>
            </Trigger>
            <Trigger Property="IsMouseOver" Value="False">
                <Setter TargetName="border" Property="Background" Value="White"/>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <ControlTemplate x:Key="ToolBarMenu_TopLevelHeader" TargetType="{x:Type MenuItem}">
        <Grid x:Name="grid" Margin="0,0,0,0">

            <Border x:Name="border" 
                CornerRadius="0" 
                Style="{StaticResource MouseOverBorder}"
                Cursor="Hand" 
                Margin="0,0,3,0"
                MinWidth="{TemplateBinding MinWidth}" MaxWidth="{TemplateBinding MaxWidth}">
                <Grid >
                    <Grid.RowDefinitions>
                        <RowDefinition Height="38"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>
                    <ContentPresenter Grid.Row="0" ContentSource="Icon" Margin="0,0,0,0" HorizontalAlignment="Center" VerticalAlignment="Center" />

                    <!--<TextBlock Grid.Row="1"
                               Margin="0,3,0,0"
                               FontSize="{StaticResource SmallFontSize}" Text="{TemplateBinding Header}" FontFamily="Arial" TextAlignment="Center" TextWrapping="Wrap" Foreground="{StaticResource ToolBarItemBrush}" />-->
                    
                    <ContentPresenter Grid.Row="1" ContentSource="Header" 
                                      TextBlock.FontFamily="Arial" TextBlock.FontSize="{StaticResource SmallFontSize}"
                                      RecognizesAccessKey="True" HorizontalAlignment="Center" VerticalAlignment="Center">                        
                    <ContentPresenter.Resources>
                        <Style TargetType="{x:Type TextBlock}">
                            <Setter Property="TextAlignment" Value="Center"/>
                                <Setter Property="TextWrapping" Value="Wrap"/>
                                <Setter Property="Foreground" Value="{StaticResource ToolBarItemBrush}"/>
                        </Style>
                    </ContentPresenter.Resources>
                </ContentPresenter>
                    
                </Grid>
            </Border>
            <Popup 
                                    Name="Popup"
                                    Placement="Bottom"                                    
                                    StaysOpen="True"               
                                    IsOpen="{TemplateBinding IsSubmenuOpen}"
                                    AllowsTransparency="True" 
                                    Focusable="False"
                                    PopupAnimation="Fade">
                <Border
                                        Margin="0,0,5,5"
                                        CornerRadius="0"
                                        Name="SubmenuBorder"                              
                                        Background="{StaticResource ToolBarMenuDropDownBackground}"
                                        BorderBrush="{StaticResource ToolBarMenuBorderBrush}"
                                        BorderThickness="2">
                    <StackPanel                                            
                                            IsItemsHost="True"
                                            KeyboardNavigation.DirectionalNavigation="Cycle" />
                    <Border.Effect>
                        <DropShadowEffect ShadowDepth="2" Opacity="0.5" />
                    </Border.Effect>
                </Border>
            </Popup>
        </Grid>

        <ControlTemplate.Triggers>
            
            <Trigger Property="IsEnabled" Value="False">
                <Setter TargetName="border" Property="Opacity" Value="0.5"/>
            </Trigger>

           

        </ControlTemplate.Triggers>

    </ControlTemplate>

    <Style x:Key="Toolbar_MenuItemStyle" TargetType="{x:Type MenuItem}">
        <Setter Property="OverridesDefaultStyle" Value="True"/>
        <Setter Property="Margin" Value="0,0,0,0"/>
        <Setter Property="MinWidth" Value="80"/>
        <Setter Property="MaxWidth" Value="80"/>
        <Setter Property="ItemContainerStyle">
            <Setter.Value>
                <Style TargetType="{x:Type MenuItem}">
                    <Setter Property="Template" Value="{StaticResource ToolBarMenu_SubmenuItem}"/>
                </Style>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <Trigger Property="Role" Value="TopLevelHeader">
                <Setter Property="Template" Value="{StaticResource ToolBarMenu_TopLevelHeader}"/>
                <Setter Property="Grid.IsSharedSizeScope" Value="true"/>
            </Trigger>
            <Trigger Property="Role" Value="TopLevelItem">
                <Setter Property="Template" Value="{StaticResource ToolBarMenu_TopLevelItem}"/>
            </Trigger>
            <Trigger Property="Role" Value="SubmenuHeader">
                <Setter Property="Template" Value="{StaticResource ToolBarMenu_SubmenuItem}"/>
            </Trigger>
            <Trigger Property="Role" Value="SubmenuItem">
                <Setter Property="Template" Value="{StaticResource ToolBarMenu_TopLevelItem}"/>
            </Trigger>
        </Style.Triggers>
    </Style>

    <Style x:Key="Toolbar_MenuItemStyleHideWhenDisabled" TargetType="MenuItem" BasedOn="{StaticResource Toolbar_MenuItemStyle}">
        <Style.Triggers>
            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="Visibility" Value="Collapsed"/>
            </Trigger>
        </Style.Triggers>
    </Style>

    <Style x:Key="GoBackMenuItem" TargetType="{x:Type MenuItem}" BasedOn="{StaticResource Toolbar_MenuItemStyle}" x:Shared="false">
        <Setter Property="Focusable" Value="False"/>
        <Setter Property="Header" Value="{x:Static props:Resources.Back}"/>
        <Setter Property="Command" Value="{Binding CloseWindowCommand}"/>
        <Setter Property="Icon">
            <Setter.Value>
                <Image Source="/Images/ToolBar/Back.png" Width="32" Height="32" Stretch="Uniform" />
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>